import 'package:flutter/material.dart';
import 'package:power_house/widgets/common_form_item.dart';

/// =>和(){}方法块的区别
/// =>相当于Kotlin中函数只有一行，并且需要返回值时用=代替方法块的逻辑
/// (){}相当于正常的函数方法体

class CommonRadioFormItem extends StatelessWidget {
  final String label;
  final List<String> options;
  final int value;
  final ValueChanged onChange;

  const CommonRadioFormItem({Key? key, required this.label, required this.options, required this.value, required this.onChange}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CommonFormItem(
      label: label,
      contentBuilder: (context) => Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: List.generate(
              options.length,
              (index) => Row(
                    children: [
                      Radio(
                        value: index,
                        onChanged: onChange,
                        groupValue: value,
                      ),
                      Text(options[index])
                    ],
                  ))),
    );
  }
}
